<script>
	export default {
		onLaunch: function() {
			this.getOpenid()
		},
		onShow: function() {

		},
		onHide: function() {

		},
		methods: {
			getOpenid() {
				uni.login({
					provider: 'weixin',
					success: (res) => {
						if (res.code) {
							// 将获取到的code发送到后端
							uni.request({
								url: 'https://tangyun.tangyuntech.com/PlatformApi/GetWeChatOpenInfoByCode', // 后端接口地址，需替换为实际地址
								method: 'GET',
								data: {
									code: res.code
								},
								success: (response) => {
									console.log(response);
									const openid = response.data.data.openid;
									wx.setStorageSync('openid', openid);
									console.log('获取到的openid:', openid);
								},
								fail: (err) => {
									console.error('请求后端接口失败', err);
								}
							});
						} else {
							console.error('获取code失败', res.errMsg);
						}
					},
					fail: (err) => {
						console.error('登录失败', err);
					}
				});
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
	@font-face {
	  font-family: 'iconfont';  /* Project id 4999024 */
	  src: url('//at.alicdn.com/t/c/font_4999024_u67vxn7hhej.woff2?t=1755942985521') format('woff2'),
	       url('//at.alicdn.com/t/c/font_4999024_u67vxn7hhej.woff?t=1755942985521') format('woff'),
	       url('//at.alicdn.com/t/c/font_4999024_u67vxn7hhej.ttf?t=1755942985521') format('truetype');
	}

	.iconfont {
		font-family: "iconfont" !important;
		font-size: 22px;
		font-style: normal;
		display: inline-block;
		margin-bottom: 5px;
		-webkit-font-smoothing: antialiased;
		-webkit-text-stroke-width: 0.2px;
		-moz-osx-font-smoothing: grayscale;
	}
	button {
	  border: none !important;
	}
	
	/* 清除按钮点击态的边框 */
	button::after {
	  border: none !important;
	}
</style>